'use strict';
import {Inject, Controller, Body, Post} from '@midwayjs/decorator';
import { Context } from '@midwayjs/koa';
import { RoleService } from '../service/roleService';
@Controller('/role')
export class RoleController {
  @Inject()
  ctx: Context;
  @Inject()
  roleService: RoleService;

  @Post('/list')
  async roleList() {
    const roleList = await this.roleService.getList()
    return roleList;
  }

  @Post('/save')
  async roleSave(@Body('roleData') data: object) {
    const rs = await this.roleService.save(data).catch(err => {
      return {
        success: false,
        msg:'保存失败'
      }
    })
    return rs
  }

  @Post('/delete')
  async roleDelete(@Body('id') id:string){
    const rs=await this.roleService.delete(id).catch(err=>{
      console.log('删除失败：',err);
      return {
        success: false,
        msg:'删除失败！'
      }
    })
    return rs
  }

}

